package com.ksd.modules.sysparameter.controller;

import com.ksd.common.controller.BaseController;
import com.ksd.common.core.result.R;
import com.ksd.modules.sysparameter.entity.SysParameter;
import com.ksd.modules.sysparameter.po.SysParamsSearchPo;
import com.ksd.modules.sysparameter.service.ISysParameterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 系统参数 前端控制器
 * </p>
 *
 * @author Auto Generator
 * @since 2023-08-24
 */
@RestController
public class SysParameterController extends BaseController {

    @Autowired
    private ISysParameterService sysParameterService;

    /**
     * 查询参数列表
     * @param sysParamsSearchPo
     * @return
     */
    @PostMapping("/sys/paramster/list")
    public R<List<SysParameter>> findSysParameters(@RequestBody SysParamsSearchPo sysParamsSearchPo){
        return R.data(sysParameterService.findSysParameters(sysParamsSearchPo));
    }

    /**
     * 同步更新数据
     * @param sysParameter
     * @return
     */
    @PostMapping("/sys/paramster/saveupdate")
    public R<Boolean> saveUpdate(@RequestBody SysParameter sysParameter){
        return R.data(sysParameterService.saveOrUpdate(sysParameter));
    }

    /**
     * 同步缓存
     * @param sysParameter
     * @return
     */
    @PostMapping("/sys/paramster/cache")
    public R<Boolean> findSysParameters(@RequestBody SysParameter sysParameter){
        return R.data(sysParameterService.saveOrUpdate(sysParameter));
    }

    /**
     * 根据ID删除
     * @param id
     * @return
     */
    @PostMapping("/sys/paramster/del/{id}")
    public R<Boolean> findSysParameters(@PathVariable("id")Long id){
        return R.data(sysParameterService.removeById(id));
    }
}
